<template>
  <a-card :bordered='false' class='card-area'>
    <!-- 查询区域 11111-->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' :label-col='labelCol' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :md='6' :sm='8'>
            <a-form-item label='会员名称'>
              <a-input placeholder='请输入会员名称' v-model='queryParam.memberName'></a-input>
            </a-form-item>
          </a-col>
          <a-col :md='5' :sm='8'>
            <a-form-item label='服务状态'>
              <a-select v-model='queryParam.orderStatus' placeholder='请选择服务状态'>
                <a-select-option value=''>请选择</a-select-option>
                <a-select-option value='1'>待接订单</a-select-option>
                <a-select-option value='2'>待服务</a-select-option>
                <a-select-option value='3'>服务中</a-select-option>
                <a-select-option value='4'>待评价</a-select-option>
                <a-select-option value='5'>已评价</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <a-col :md='5' :sm='8'>
            <a-form-item label='定制类型'>
              <!--   /** 1 居家护工  2住院护工 3陪诊师 4康复师 5挂号服务 6其他服务 */-->
              <a-select v-model='queryParam.customType' placeholder='请选择定制类型'>
                <a-select-option value=''>请选择</a-select-option>
                <a-select-option value='1'>居家护工</a-select-option>
                <a-select-option value='2'>住院护工</a-select-option>
                <a-select-option value='3'>陪诊师</a-select-option>
                <a-select-option value='4'>康复师</a-select-option>
                <a-select-option value='5'>挂号服务</a-select-option>
                <a-select-option value='6'>其他服务</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>
          <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
           <a-col :md='6' :sm='24'>
               <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
               <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
           </a-col>
        </span>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
<!--      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>-->
<!--      <a-dropdown v-if='selectedRowKeys.length > 0'>-->
<!--        <a-menu slot='overlay'>-->
<!--          <a-menu-item key='1' @click='batchDel'>-->
<!--            <a-icon type='delete' />-->
<!--            删除-->
<!--          </a-menu-item>-->
<!--        </a-menu>-->
<!--        <a-button style='margin-left: 8px'> 批量操作-->
<!--          <a-icon type='down' />-->
<!--        </a-button>-->
<!--      </a-dropdown>-->
    </div>

    <!-- table区域-begin -->
    <div>
<!--      <div class='ant-alert ant-alert-info' style='margin-bottom: 16px;'>-->
<!--        <i class='anticon anticon-info-circle ant-alert-icon'></i>-->
<!--        <span>已选择</span>-->
<!--        <a style='font-weight: 600'>-->
<!--          {{ selectedRowKeys.length }}-->
<!--        </a>-->
<!--        <span>项</span>-->
<!--        <a style='margin-left: 24px' @click='onClearSelected'>清空</a>-->
<!--      </div>-->

      <a-table
        ref='table'
        size='middle'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :scroll="{x:1600}"
        @change='handleTableChange'>

        <span slot='action' slot-scope='text, record'>
           <a @click="handleEdit(record)">详情</a>
           <a-divider type='vertical' v-if='record.confirmStatus==1'/>
           <a @click='showModal(record.id)' v-if='record.confirmStatus==1'>待接单</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->
    <custom-order-modal ref="modalForm"></custom-order-modal>
    <!-- 表单区域 -->
    <a-modal :maskClosable="false" v-model="visible" title="确认接单" ok-text="确认" cancel-text="取消" @ok="hideModal">
      <a-row>
        <h4>费用:</h4> <a-input prefix="￥" suffix="元" v-model="amount" />
      </a-row>
    </a-modal>
  </a-card>
</template>
<script>
import '@assets/less/TableExpand.less'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { putAction, getAction, postAction } from '@api/manage'
import { frozenBatch } from '@api/api'
import CustomOrderModal from './modules/CustomOrderModal'

export default {
  name: 'h_ch_care_door_orderList',
  mixins: [JeecgListMixin],
  components: {
    CustomOrderModal
  },
  data() {
    return {
      description: '上门服务订单管理页面',
      labelCol: { style: { width: '110px' } },
      queryParam:{
       //3上门护理 4上门照护 5陪诊服务 6慢性康复 7营养指导  10慢性
        orderType:"6"
      },
      visible: false,
      amount:0,
      // 表头
      columns: [
        {
          title: '会员名称',
          align: 'center',
          dataIndex: 'memberName',
          width: 130,
        },
        {
          title: '定制类型',
          align: 'center',
          dataIndex: 'customType',
          width: 150,
          customRender: function(t, r, index) {
            /** 1 居家护工  2住院护工 3陪诊师 4康复师 5挂号服务 6其他服务 */
             if(t=="1"){
               return "居家护工";
             }else  if(t=="2"){
               return "住院护工";
             }else  if(t=="3"){
               return "陪诊师";
             }  else  if(t=="4"){
               return "陪诊师";
             }else  if(t=="5"){
               return "挂号服务";
             }
             return "其他服务";
          }
        },
        {
          title: '被服务对像年龄',
          align: 'center',
          dataIndex: 'patientAge',
          width: 150,
          customRender: function(t, r, index) {
            return r.beanInfoDto.patientAge+" 岁";
          }
        },
        {
          title: '被服务对像省市区',
          align: 'center',
          dataIndex: 'beanInfoDto',
          width: 150,
          customRender: function(t, r, index) {
            return t.provinceName+t.cityName+t.districtName
          }
        },
        {
          title: '订单状态',
          align: 'center',
          dataIndex: 'orderStatus',
          width: 100,
          /** 状态，0等接单，1己接单，2客户己取消 3商家取消 */
          customRender: function(t, r, index) {
            /** 1 居家护工  2住院护工 3陪诊师 4康复师 5挂号服务 6其他服务 */
            if(t=="0"){
              return "等接单";
            }else  if(t=="1"){
              return "己接单";
            }else  if(t=="2"){
              return "客户己取消";
            }  else  if(t=="3"){
              return "商家取消";
            }
            return "";
          }
        },
        {
          title: '总费用(元)',
          align: 'center',
          dataIndex: 'amount',
          width: 100,
          customRender: function(t, r, index) {
            if(t==null||t==0){
              return "待商议"
            }
            return t;
          }
        },
        {
          title: '服务状态',
          align: 'center',
          dataIndex: 'confirmStatus',
          width: 100,
          customRender: function(t, r, index) {
            /** 订单服务状态，1 待接订单  2 待服务 3 服务中  4 待评价 */
            if(t=="1"){
              return "待接订单";
            }else  if(t=="2"){
              return "待服务";
            }else  if(t=="3"){
              return "服务中 ";
            }else  if(t=="4"){
              return "待评价 ";
            }
            return "已完成";
          }
        },
        {
          title: '接单人员',
          align: 'center',
          dataIndex: 'confirmUser',
          width: 130,
          customRender: function(t, r, index) {
            if(t==''){
              return "---"
            }
            return t;
          }
        },
        {
          title: '备注',
          align: 'center',
          customRender: function(t, r, index) {
            return r.beanInfoDto.remark;
          }
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime',
          width: 150,
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' },
          fixed:"right",
          width: 120,
        }
      ],
      url: {
        list: '/store/order/list/customized',
      },
      id:0,
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    showModal(id) {
      this.visible = true;
      this.id=id;
    },
    hideModal() {
      const that=this;
      that.visible = false;
      if(that.amount>0){
        postAction("/store/order/customized/confirm",{id:this.id,amount:that.amount}).then((res) => {
          if (res.success) {
               that.$message.success(res.message);
               that.loadData();
               that.onClearSelected();
          }else{
               that.$message.error(res.message);
          }
          that.id=0;
        })
      }

    },
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>